package com.example.service;

import com.example.domain.Bady;
import com.example.respository.BadyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by 李强 on 2017/5/6.
 */
@Service
public class BadyService {

    @Autowired
    private BadyRepository badyRepository;

    @Transactional

    public void inserTow(){
       Bady badyA=new Bady();
       badyA.setName("李四");
       badyA.setAge(18);
       badyRepository.save(badyA);

       Bady badyB=new Bady();
       badyB.setAge(19);
       badyB.setName("王五");
       badyRepository.save(badyB);


   }

   public void getAge(Integer id) throws Exception{
        Bady bady =badyRepository.findOne(id);
        Integer age =bady.getAge();
        if (age<10){
            throw new Exception("上小学");
        } else if (age>10&&age<16){
            throw new Exception("上初中");
        }

   }

}
